/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustProtect;
import com.sasis.dao.FlightAdjustProtectDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustProtectDaoiBatis extends BaseDaoiBATIS implements FlightAdjustProtectDao {

    /**
     * @see com.sasis.dao.FlightAdjustProtectDao#getFlightAdjustProtects(com.sasis.model.FlightAdjustProtect)
     */
    public List getFlightAdjustProtects(final FlightAdjustProtect flightAdjustProtect) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustProtects", flightAdjustProtect);
    }

    /**
     * @see com.sasis.dao.FlightAdjustProtectDao#getFlightAdjustProtect(Integer id)
     */
    public FlightAdjustProtect getFlightAdjustProtect(Integer id) {
        FlightAdjustProtect flightAdjustProtect = (FlightAdjustProtect) getSqlMapClientTemplate().queryForObject("getFlightAdjustProtect", id);

        //if (flightAdjustProtect == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustProtect.class, id);
        //}

        return flightAdjustProtect;
    }

    /**
     * @see com.sasis.dao.FlightAdjustProtectDao#saveFlightAdjustProtect(FlightAdjustProtect flightAdjustProtect)
     */    
    public int saveFlightAdjustProtect(final FlightAdjustProtect flightAdjustProtect) {
        Integer id = flightAdjustProtect.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustProtect", flightAdjustProtect);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustProtect", flightAdjustProtect);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustProtect.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustProtectDao#removeFlightAdjustProtect(Integer id)
     */
    public void removeFlightAdjustProtect(FlightAdjustProtect flightAdjustProtect) {
        getSqlMapClientTemplate().update("deleteFlightAdjustProtect",  flightAdjustProtect);
    }
}
